// Remove all handlers
player removeAllEventHandlers "Take";
player removeAllEventHandlers "Put";
player removeAllEventHandlers "InventoryOpened";
player removeAllEventHandlers "Hit";
player removeAllEventHandlers "Killed";
player removeAllEventHandlers "Respawn";
player removeAllEventHandlers "HandleDamage";

player addEventHandler ["Killed",{

		// 事件触发者
		_unit = _this select 1;
		// 被杀
		_killer = _this select 1;
		// 扣动扳机的人
		_instigator = _this select 2;

		

		if (!isNull _instigator) then {
			_killer = _instigator;
		};

		[] spawn M4_fnc_playerExState;

		// 发送信息给杀手说他杀了人
		if ((_this select 0) != _killer && !isNull (_this select 0) && (!isNull _killer)) then {
			[-0.03184] remoteExec ["M4_fnc_kill",_killer];
			KillTotal = KillTotal+1;
			player setVariable ["Destiny_kill_sum",KillTotal];
			// 你被消息杀死了
			//[format ["You have been killed by<br/>%1", (_killer getVariable ["name", ""])]] spawn client_fnc_displayInfo;

		};
}];

player addEventHandler ["Hit",{
	params  [ "_unit" ,  "_source" ,  "_damage" ,  "_instigator" ]; 
	// Killer
	
	systemChat str _damage;

	[_damage] remoteExec ["M4_fnc_test",_instigator];

	
	_d = [_this select 0, _this select 1] call BIS_fnc_relativeDirTo;
	if (_d >= 315 || _d <= 45) then {351 cutRsc ["cu","PLAIN"];};
	if (_d >= 45 AND _d <= 135) then {352 cutRsc ["cr","PLAIN"];};
	if (_d >= 135 AND _d <= 225) then {353 cutRsc ["cd","PLAIN"];};
	if (_d >= 225 AND _d <= 315) then {354 cutRsc ["cl","PLAIN"];};
	if ((_this select 1) == player) then {
		351 cutRsc ["cu","PLAIN"];
		352 cutRsc ["cr","PLAIN"];
		353 cutRsc ["cd","PLAIN"];
		354 cutRsc ["cl","PLAIN"];
	};
}];

player addEventHandler ["Put", {
	params ["_unit", "_container", "_item"];
	hint "Put";
	[player] call M4_fnc_savePlayerInfo;
}];

player addEventHandler ["Take", {
	params ["_unit", "_container", "_item"];
	hint "Take";
	[player] call M4_fnc_savePlayerInfo;
}];



player addEventHandler ["Respawn", {
	params ["_unit", "_corpse"];
	//关闭定时器
	KSS_hunger = 100;
	KSS_thirst = 100;
	[] spawn Destiny_fnc_timerStop;
	call M4_fnc_setupEventHandlers;
	call M4_fnc_createBox;
	
}];


(findDisplay 46) displayAddEventHandler ["KeyDown", {
	params ["_displayOrControl", "_key", "_shift", "_ctrl", "_alt"];

	if (_key == 1) then {
		[getPlayerUID player, crate] spawn dnct_fnc_SaveContainer;
		[player] call M4_fnc_savePlayerInfo;
		
	};
}];